import anim_util from "./anim_util";
import constants from "./constants";
import GameController from "./game_controller";
import global from "./global";
import wx_opendata from "./wx/wx_opendata";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

declare const wx;
declare const canvas;

@ccclass
export default class NewClass extends cc.Component {

   

    @property(cc.Node)
    bg:cc.Node=null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // cc.log("wewew");
        if(CC_WECHATGAME){
            wx.onShow(res => {
                let shareTicket = res.shareTicket;
                if(shareTicket){
                     global.shareTicket=shareTicket;
                     global.rankingState=global.RankingState.Group;
                     cc.director.loadScene("ranking");
                }
    
    
            });
            wx.updateShareMenu({
                withShareTicket: true
              });
            wx.showShareMenu();
            wx.onShareAppMessage(
                function(){
                    return {
                        title : "我正在玩这个游戏...",
                        imageUrl: canvas.toTempFilePathSync({
                            destWidth: 500,
                            destHeight: 400
                          })
                    }
                }
            );
 
            const button = wx.createGameClubButton({
                icon: 'white',
                style: {
                  left: 20,
                  top: wx.getSystemInfoSync().screenHeight-70,
                  width: 40,
                  height: 40
                }
              });
              button.show();
        }
    
        cc.director.preloadScene("main");
    }

    start () {

    }

    onClickFriendBtn(){
        global.rankingState=global.RankingState.Friend;
        global.rankingCallBackScene="start";
        cc.director.loadScene("ranking");
    }

    onClickGroupBtn(){
        cc.director.emit(constants.GAME_EVENT.BtnClick);
        wx_opendata.wxShare();
    }

    // update (dt) {}
}
